package com.wanger.swa.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wanger.swc.model.Result;
import com.wanger.swa.domain.myEnum.DataSourceEnum;
import com.wanger.swa.dto.dataSource.query.DataSourceQuery;
import com.wanger.swa.dto.dataSource.req.DataSourceAddReq;
import com.wanger.swa.dto.dataSource.req.DataSourceUpdateReq;
import com.wanger.swa.dto.dataSource.resp.DataSourceActualContentResp;
import com.wanger.swa.dto.dataSource.resp.DataSourceResp;
import com.wanger.swa.dto.dataSource.resp.SupportTypeResp;
import com.wanger.swa.service.ise.DataSourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: wanger
 * @Date: 2024/9/15 12:52
 * @Description: 数据源
 */
@RestController
@Api(tags = "数据源")
@RequiredArgsConstructor
@RequestMapping("/dataSource")
public class DataSourceController {

    private final DataSourceService dataSourceService;

    @ApiOperation("添加数据源")
    @PostMapping("/addDataSource")
    public Result<DataSourceResp> addDataSource(@RequestBody DataSourceAddReq addDTO) {
        return Result.ok(dataSourceService.addDataSource(addDTO));
    }

    @ApiOperation("修改数据源")
    @PutMapping("/updateDataSource")
    public Result<DataSourceResp> updateDataSource(@RequestBody DataSourceUpdateReq updateDTO) {
        return Result.ok(dataSourceService.updateDataSource(updateDTO));
    }

    @ApiOperation("数据源详情")
    @GetMapping("/getOneDataSource")
    public Result<DataSourceResp> getOneDataSource(String id) {
        return Result.ok(dataSourceService.getOneDataSource(id));
    }

    @ApiOperation("分页查询数据源")
    @GetMapping("/pageDataSource")
    public Result<IPage<DataSourceResp>> pageDataSource(DataSourceQuery query) {
        return Result.ok(dataSourceService.pageDataSource(query));
    }

    @ApiOperation("数据源列表查询")
    @GetMapping("/listDataSource")
    public Result<List<DataSourceResp>> listDataSource(DataSourceQuery query) {
        return Result.ok(dataSourceService.listDataSource(query));
    }

    @ApiOperation("删除数据源")
    @DeleteMapping("/deleteDataSource")
    public Result<Void> deleteDataSource(String id) {
        dataSourceService.deleteDataSource(id);
        return Result.ok();
    }

    @ApiOperation("数据源枚举")
    @GetMapping("/getEnumDataSource")
    public Result<Map<String, List<Map<String, String>>>> getEnumDataSource() {
        return Result.ok(DataSourceEnum.getList());
    }

    @ApiOperation("获取支持类型")
    @GetMapping("/getSupportType")
    public Result<List<SupportTypeResp>> getSupportType() {
        return Result.ok(dataSourceService.getSupportType());
    }

    @ApiOperation("查询数据源内容")
    @GetMapping("/getDataSourceById")
    public Result<DataSourceActualContentResp> getDataSourceById(String id) {
        return Result.ok(dataSourceService.getDataSourceById(id));
    }

    @ApiOperation("数据验证")
    @PostMapping("/dataVerification")
    public Result<Void> dataVerification(@RequestBody DataSourceAddReq addDTO) {
        dataSourceService.dataVerification(addDTO);
        return Result.ok();
    }
}
